<?php
/**
 * Created by PhpStorm.
 * User: hooshim
 * Date: 2014-12-03
 * Time: 오전 11:23
 */

header("Content-Type:text/html;charset=utf-8");
header("Cache-Control:no-cache");
header("Pragma:no-cache");

include_once ($_SERVER['DOCUMENT_ROOT']."/inc/conn.inc.php");
include_once ($_SERVER['DOCUMENT_ROOT']."/inc/function.inc.php"); ##property 파일 인크루드됨.

	//## 파라미터 선언

    $invoiceCd 		= $_POST['invoiceCd'];
    $compCd 		= $_POST['compCd'];
    $owner 	    	= $_POST['owner'];
    $issueDt 	    = $_POST['issueDt'];
    $amount 		= $_POST['amount'];
    $orgAmount 		= $_POST['orgAmount'];
    $tax 			= $_POST['tax'];
    $incomeDt 		= $_POST['incomeDt'];
    $major 			= $_POST['major'];
    $majorPhone 	= $_POST['majorPhone'];
    $remarks 		= $_POST['remarks'];
    $flag 			= $_POST['flag'];

    if($owner) $owner = iconvEncode($owner);
    if($remarks) $remarks = iconvEncode($remarks);
    if($major) $major = iconvEncode($major);

    if(!$amount) $amount = 0;
    if(!$orgAmount) $orgAmount = 0;
    if(!$tax) $tax = 0;
    if(!$compCd) $compCd = 0;
    if(!$invoiceCd) $invoiceCd = 0;

    if(!$issueId) $issueId = "Jade";

    $query = "EXEC spInvoice ";

    $query .=" @compCd='" .$compCd ."'";
    $query .=", @amount='" .$amount ."'";
    $query .=", @orgAmount='" .$orgAmount ."'";
    $query .=", @tax='" .$tax ."'";
    $query .=", @incomeDt='" .$incomeDt ."'";
    $query .=", @flag='" .$flag ."'";
    $query .=", @issueDt='" .$issueDt ."'";
    $query .=", @owner='" .$owner ."'";
    $query .=", @accessId='" .$issueId ."'";
    $query .=", @invoiceCd='" .$invoiceCd ."'";
    $query .=", @major='" .$major ."'";
    $query .=", @majorPhone='" .$majorPhone ."'";

    $logger->debug($query ." [#FROM:" . $G_remote_ip."#]"); ## 결과 로그 작성
    $rslt = mssql_query($query);
    $logger->debug($rslt ." [#FROM:" . $G_remote_ip."#]");

    $result = Array();
    if ($rslt == "1") {
        $result['rsStatus'] = "Success";
        $successMsg = iconvEncode("저장 되었습니다.");
    }
    else {
        $result['rsStatus'] = "Fail";
        $successMsg = iconvEncode("저장 실패");

    }
    $result['rsStr'] = urlencode($successMsg);

    $output = json_encode($result);
    $output = urldecode($output);
    echo iconvDecode($output);
    $logger->debug($output ." [#FROM:" . $G_remote_ip."#]"); ## 결과 로그 작성
?>